<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>

<!--							<li>-->
<!--								商户名称：<select name="merchantId" id="merchantId"></select>-->
<!--							</li>-->

							<li>
								钱包类型名称：<select name="walletKindId" id="walletKindId"></select>
							</li>


							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="withdrawal()" shiro:hasPermission="merchantAccount:mpMerchantWallet:withdrawal">
					<i class="fa fa-plus"></i> 代付
				</a>
<!--				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="merchant:mpMerchantWallet:remove">-->
<!--					<i class="fa fa-remove"></i> 删除-->
<!--				</a>-->
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="merchantAccount:mpMerchantWallet:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('merchant:mpMerchantWallet:edit')}]];
        var removeFlag = [[${@permission.hasPermi('merchant:mpMerchantWallet:remove')}]];
        var prefix = ctx + "merchantAccount/wallet";
        var mpMerchant = [[${mpMerchant}]];

        $(function() {
        	// 初始化钱包、渠道、商户选项
			initSelect($("#walletKindId"),"merchantAccount/wallet/walletlist");
			// initSelect($("#merchantId"),"merchant/merchantInfo/list");

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "商户钱包",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '标识',
					visible: false
				},
				// {
				// 	field : 'merchantId',
				// 	title : '商户标识',
				// 	sortable: true,
                //     visible: false
				// },
				// {
				// 	field : 'merchantName',
				// 	title : '商户名称'
				// },
				{
					field : 'walletKindId', 
					title : '钱包类型标识',
					sortable: true,
                    visible: false
				},
				{
					field : 'walletKindName',
					title : '钱包类型名称'
				},
				{
					field : 'accountBalance', 
					title : '总金额(元)',
					sortable: true,
					formatter:function (value, row, index) {
						if(value != null){
							var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
							return data;
						}
					}
				},
                {
                    field : 'waitLiquidatedBalance',
                    title : '待结算金额(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
                            return data;
                        }
                    }
                },
				{
					field : 'frozenBalance',
					title : '冻结金额(元)',
					sortable: true,
					formatter:function (value, row, index) {
						if(value != null){
							var data = new Decimal(value).div(new Decimal(100.00)).toFixed(2);
							return data;
						}
					}
				},
                {
                    field : 'unliquidatedBalanceOne',
                    title : '未结算金额(元)',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var unliquidatedBalanceOne = new Decimal(value).div(new Decimal(100.00));
                            var unliquidatedBalanceTwo = new Decimal(row.unliquidatedBalanceTwo).div(new Decimal(100.00));
                            var data = new Decimal(unliquidatedBalanceOne).add(new Decimal(unliquidatedBalanceTwo)).toFixed(2);
                            return data;
                        }
                    }
                },
                {
                    field : 'dZero',
                    title : 'D0',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var data = value.toFixed(4);
                        return data;
                    }
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	/*actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');*/
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

        // 初始化下拉菜单选项
        function initSelect(i,url) {
			$.post(ctx + url ,function (data) {
				var option = "<option value='' selected>全部</option>";
				$.each(data.rows,function (index,value) {
					option += "<option value='"+value.id+"'>"+value.name+"</option>";
				});
				i.html(option);
			});
		}



        /**
		 * 代付
         */
        function withdrawal() {
            if(mpMerchant == null) {
                $.modal.alertError("当前用户没有绑定商户！");
                return;
			}
            var url = prefix + "/withdrawal/" + mpMerchant.id;
            $.modal.open("代付",url);
        }
    </script>
</body>
</html>